#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#include "sqlink.h"



sqlist create(void) {
    sqlist sq;
    sq=(sqlist)malloc(sizeof(sqlink));
    memset(sq,0,sizeof(sqlist));
    sq->length=0;
    return sq;
}
    int locate(sqlist sq, int index) {
        if (index >= 0 && index < sq->length)
            return sq->data[index];
        else
            printf("locate is error\n");
        exit(0);
    }

int insert(sqlist sq, int index, int data) {
    if (sq->length == maxsize) {
        printf("the table is full\n");
        return -1;
    }
    if(index < 0) {
        printf("index is error,nothing to do.\n");
        return -1;
    }
    if(index > sq->length+1) {
        printf("the index is over last\n");
        return -1;
    }
        int i;
        for(i=sq->length;i>=index && i>0 ;i--)
            sq->data[i]=sq->data[i-1];

    sq->data[index]=data;
    sq->length+=1;
    return data;
}

void printlist(sqlist sq) {
    if(sq==NULL) {
        return ;
    }
    int i;
    for(i=0;i<sq->length;i++) {
        printf("%d,",sq->data[i]);
    }
    printf("\n");
}
